
Partial Class Report
    Inherits System.Web.UI.Page


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim simId As Integer = Request.Params.Item("sId")
        Dim userId As Integer = Request.Params.Item("uId")

        If (Not Session().Item(userId.ToString) = userId) Then
            Response.Redirect("Welcome.aspx")
        End If

        

        Dim path As String = Server.MapPath(".") & "\App_Data\Downloads\"
        
        Dim reportCol As Collection = DBConnection.FET_REPORTS(simId)

        Dim row As Integer = 0
        Dim i As Integer = 0
        'key - id, value - rpt
        For Each rpt As Reporting In reportCol

            Dim cell1 As New TableCell
            If i = 0 Then
                cell1.Text = rpt.SimulationName
                i += 1
            End If

            Dim cell2 As New TableCell
            cell2.Text = rpt.ReportStatus

            Dim cell3 As New TableCell

            Dim link As New HyperLink
            link.NavigateUrl = "ReportPage.aspx?rId=" & rpt.ReportID & "&uId=" & userId & "&sId=" & simId
            link.Text = rpt.TimeStamp
            cell3.Controls.Add(link)
            Dim tr As New TableRow

            tr.Cells.Add(cell1)
            tr.Cells.Add(cell2)
            tr.Cells.Add(cell3)

            ReportTable.Rows.Add(tr)

            row += 1
        Next
        'do stuff
    End Sub


    Private Function DownloadReport(ByVal rpt As Reporting, ByVal downloads As String) As Boolean

        If Not rpt.ReportData Is Nothing Then
            Dim rptName As String = rpt.ReportName
            downloads &= rptName

            Dim fs As New IO.FileStream(downloads, IO.FileMode.Create, IO.FileAccess.Write, IO.FileShare.ReadWrite)

            fs.Write(rpt.ReportData, 0, rpt.ReportData.Length)
            fs.Close()
            fs.Dispose()
            Return True

        End If

        Return False

    End Function
End Class
